const puppeteer = require('puppeteer');

(async () => {
    let browser = await puppeteer.launch({
        headless: false,
        ignoreDefaultArgs: ["--enable-automation"]
    });
    let page = await browser.newPage();
    await page.evaluateOnNewDocument(() => {
        const newProto = navigator.__proto__;
        delete newProto.webdriver;
        navigator.__proto__ = newProto;
    });
    await page.goto('https://www.baidu.com/');
    let r = await page.evaluate(() => new Promise((resolve, reject) => {
        var body = document.getElementsByTagName("body")[0];
        var image = document.createElement("img");
        image.src = "http://iloveponeydotcom32188.jg";
        image.setAttribute("id", "fakeimage");
        body.appendChild(image);
        image.onerror = function(){
            console.log(image.width, image.height);
            return resolve(image.width);
        }
    }));
    console.log(r);
})()